package com.xoomworks.rsfr.core.service;

import java.util.List;

import com.xoomworks.rsfr.model.User;

/**
 * User service interface.
 *
 * @author bogdan.sbiera
 */
public interface UserService extends BaseService<User> {

    /**
     * Finds the User by username.
     *
     * @param username
     *            String
     * @return User with the given username or null if it is not found
     */
    public User findByUsername(String username);

    /**
     * Finds the User by email.
     *
     * @param email
     *            String
     * @return User with the given email or null if it is not found
     */
    public User getByEmail(String email);

    /**
     * Confirms the email of a newly created user and sets his password.
     *
     * @throw RuntimeException if token has expired or if token is not valid
     * @param email
     *            String
     * @param username
     *            String
     * @param password
     *            String
     * @param token
     *            String
     */
    public void confirmEmailAndSetPassword(String email, String username, String password,
            String token);

    /**
     * Saves the user details in the database then sends an email with a
     * confirmation Url. The Url should link to a page where the user can set
     * his initial password
     *
     * @param user
     *            User
     * @return user
     */
    public Long registerUser(User user);

    /**
     * Initiates the process of reseting a users password. The user will receive
     * an email with a link to a page where he can enter his new password
     *
     * @param email
     *            identifies the user
     */
    public void resetPassword(String email);

    /**
     * Returns the administrator of the Company that matches the companyId.
     *
     * @param companyId
     *            Company
     * @return User with the role of Company Administrator for the company that
     *         matches the companyId , null if the company has no administrator
     */
    public User findAdminOfCompany(Long companyId);

    /**
     * Saves the user details in the database then sends an email with a
     * confirmation Url. The Url should link to a page where the user can set
     * his initial password
     *
     * @param user
     *            User
     */
    public void inviteUser(User user);

    /**
     * Returns all the users from a company, given by id.
     *
     * @return List<User>
     */
    public List<User> findAllByCompanyId();

    /**
     * Initial setup. Made after a user receives an invitation.
     *
     * @param email
     *            the email of the user
     * @param hash
     *            is used to verify the request.
     * @param username
     *            the user's first username
     * @param companyName
     *            the user's company name
     * @param password
     *            the user's password
     */
    public void initialSetup(String email, String hash, String username, String companyName,
            String password);

    /**
     * Updates the authenticated user's password.
     *
     * @param newPassword
     *            the new password
     */
    public void updateAuthenticatedUserPassword(String newPassword);

}
